<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/mayioa/css/mayioa-ui.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/datapicker/bootstrap-datetimepicker.min.css}" rel="stylesheet"/>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-plan-config-add">
			<input name="planCfgDeptId"  type="hidden" id="treeId"/>

			<div class="form-group">
				<label class="col-sm-3 control-label">计划名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="planCfgName" id="planCfgName">
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label">部门名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="planDeptName" onclick="selectDeptTree()"  id="treeName" readonly>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">计划项目类型：</label>
				<div class="col-sm-8">
					<select id="planCfgType" class="form-control m-b" th:with="type=${@dict.getType('plan_detail_type')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">计划流程：</label>
				<div class="col-sm-8">
					<select id="planCfgFlowName" name="planCfgFlowName" class="form-control m-b">
						<option value="">-&#45;&#45;请选择-&#45;&#45;</option>
						<option th:each="flow:${flowList}" th:value="${flow['planFlowId']}" th:text="${flow['planFlowFileName']}"></option>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">计划约束：</label>
				<div class="col-sm-8">
					<select id="planCfgCond" name="planCfgCond" class="form-control select2-hidden-accessible" multiple="">
						<option th:each="cond:${conditions}" th:value="${cond.planCstrId}" th:text="${cond.planCstrName}"></option>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">通过分数：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="planCfgPassScore" id="planCfgPassScore">
				</div>
			</div>

			<div class="form-group">
					<label class="col-sm-3 control-label">计划开始时间：</label>
					<div class="col-sm-8" style="padding:0 28px;">
						<div class="form-group">
							<div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
								<input type="text" id="planCfgStartTime" name="planCfgStartTime" class="form-control" value="" readonly style="background:#fff;">
							</div>
						</div>
					</div>
			</div>

			<div class="form-group">
					<label class="col-sm-3 control-label">计划结束时间：</label>
					<div class="col-sm-8" style="padding:0 28px;">
						<div class="form-group">
							<div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
								<input type="text" id="planCfgEndTime" name="planCfgEndTime" class="form-control" value="" readonly style="background:#fff;">
							</div>
						</div>
					</div>
			</div>
		
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="planCfgRemark" name="planCfgRemark" class="form-control"></textarea>
				</div>
			</div>
		</form>
	</div>
	
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script th:src="@{/js/jquery-ui-1.10.4.min.js}"></script>
	<script th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
	<script th:src="@{/ajax/libs/datapicker/bootstrap-datetimepicker.min.js}"></script>
	<script th:src="@{/ajax/libs/beautifyhtml/beautifyhtml.js}"></script>
	<script>
		
		function typeChange() {
			
		}
		 $.fn.datetimepicker.dates['zh-CN'] = {
	             days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
	             daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
	             daysMin:  ["日", "一", "二", "三", "四", "五", "六", "日"],
	             months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
	             monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
	             today: "今日",
	             suffix: [],
	             meridiem: ["上午", "下午"],
	             weekStart: 1
	     };
		 $("#planCfgStartTime").datetimepicker({
			language:"zh-CN",
		    format: "yyyy-mm-dd hh:ii",
		    language: 'zh-CN',
		    todayHighlight:true,
		    startDate:new Date(),
		    autoclose: true ,
		    keyboardNavigation: !1,
			forceParse: !1,
			todayBtn: "linked",
			calendarWeeks: !0
		}).on('changeDate',function(ev){
			  var starttime=$("#planCfgStartTime").val();
			  $("#planCfgEndTime").datetimepicker('setStartDate',starttime);
			  $("#planCfgStartTime").datetimepicker('hide');
	    });
			
		$("#planCfgEndTime").datetimepicker({
			 language:"zh-CN",
			 format: "yyyy-mm-dd hh:ii", 
			 language: 'zh-CN',
			 todayHighlight:true,
			 startDate:new Date(),
			 autoclose: true ,
			 keyboardNavigation: !1,
			 forceParse: !1,
			 todayBtn: "linked",
			 calendarWeeks: !0
		}).on('changeDate',function(ev){
			  var starttime=$("#planCfgStartTime").val();
			  var endtime=$("#planCfgEndTime").val();
			  $("#planCfgStartTime").datetimepicker('setEndDate',endtime);
			  $("#planCfgEndTime").datetimepicker('hide'); 
		});
		

        $("#form-plan-config-add").validate({
        	rules:{
        		planCfgName:{
        			required:true,
        			maxlength: 255,
        			remote: {
                        url: ctx + "plan/config/checkPlanCfgNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.common.trim($("#planCfgName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		planDeptName:{
        			required:true
        		},
        		planCfgPassScore:{
        			required:true,
        			number:true
        		},
        		planCfgStartTime:{
        			required:true
        		},
        		planCfgEndTime:{
        			required:true
        		},
        		messages: {
					"planCfgName": {
						remote: "计划名称已经存在"
					}
				}
            }
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }

        function add() {
        	var planCfgName = $("input[name='planCfgName']").val();
        	var planCfgDeptId = $("input[name='planCfgDeptId']").val();
        	var planCfgType = $("#planCfgType option:selected").val();
        	var planCfgFlowId = $("#planCfgFlowName option:selected").val();
        	var planCfgPassScore = $("input[name='planCfgPassScore']").val();
        	var planCfgStartTime = $("input[name='planCfgStartTime']").val();
        	var planCfgEndTime = $("input[name='planCfgEndTime']").val();
        	var planCfgRemark = $("#planCfgRemark").val();
        	var condIds = $.form.selectSelects("planCfgCond");
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "plan/config/add",
        		data : {
        			"planCfgName": planCfgName,
        			"planCfgDeptId": planCfgDeptId,
        			"planCfgType": planCfgType,
        			"planCfgFlowId": planCfgFlowId,
        			"planCfgPassScore": planCfgPassScore,
        			"planCfgStartTime": planCfgStartTime,
        			"planCfgEndTime": planCfgEndTime,
        			"planCfgRemark": planCfgRemark,
        			"condIds": condIds
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }

        /*选择部门树*/
        function selectDeptTree() {
        	var treeId = $("#treeId").val();
        	var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        	var url = ctx + "system/dept/selectDeptTree/" + deptId;
			var options = {
				title: '选择部门',
				width: "380",
				url: ctx + "system/dept/selectDeptTree/" + deptId,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			<!--if ($.tree.notAllowParents(tree)) {-->
				var body = layer.getChildFrame('body', index);
    			$("#treeId").val(body.find('#treeId').val());
    			$("#treeName").val(body.find('#treeName').val());
    			layer.close(index);
			<!--}-->
		}
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }
    </script>
</body>
</html>
